Transfom represent kinds of transform matrixes, including translation, scaling, rotation and projection.
from py3d import Transform
Transform()
Welcome to py3d world, please visit https://tumiz.github.io/scenario/ for more information
Transform([[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]])
Transform(n=(2,))
Transform([[[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]],
[[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]]])
In py3d, transformations are represented as left-multiplication matrixes, point are represented as row vectors.
from sympy import symbols, Matrix
x, y, z, dx, dy, dz = symbols("x y z dx dy dz")
point = Matrix([x, y, z, 1]).T
translation = Matrix([
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[dx, dy, dz, 1]
])
translation
point * translation
dx_,dy_,dz_ = symbols("dx' dy' dz'")
translation_ = Matrix([
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[dx_, dy_, dz_, 1]
])
translation_ * translation
translation * translation_
translation.T
translation.T * point.T
from py3d import Vector3
Vector3([2, 3, 4]).as_translation()
Transform([[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[2., 3., 4., 1.]])
Transform.from_translation(x=1, n=(2,))
Transform([[[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[1., 0., 0., 1.]],
[[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[1., 0., 0., 1.]]])
Translate a series of points
import py3d
v = py3d.Viewer()
points = py3d.Vector3.Rand(100)
v.render(points.as_point())
points @= py3d.Transform.from_translation(x=1)
v.render(points.as_point())
v.show()
Move a car
import py3d
v = py3d.Viewer()
car = py3d.Utils.Car()
grid = py3d.Utils.Grid(10)
t = 0
while t < 4:
car.vertex @= py3d.Transform.from_translation(x=0.2)
v.render(grid, car, t=t)
t += 0.1
v.show()